<%@ page language="java" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>设备健康概览</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
<%@include file="\refers.jsp" %>
<script type="text/javascript" src="<%=basePath%>chartsJs/uxmedia.js"></script>
<script type="text/javascript" src="<%=basePath%>chartsJs/uxflash.js"></script>
<script type="text/javascript" src="<%=basePath%>chartsJs/uxchart.js"></script>
<script type="text/javascript" src="<%=basePath%>chartsJs/uxfusion.js"></script>
<script type="text/javascript">
var startD;
var endD;
Ext.onReady(function(){
	var devTree = new Ext.tree.TreePanel({
		title:'设备列表',
		region:'west',
		width:160,
		minSize: 120,
		maxSize: 180,
		animate:false,
		border:false,
		split:true,
		collapsible: true,
		id:'devTree',
		autoScroll:true,
		lines:true,
		rootVisible:false,
		root:{
			text:'设备列表',
			draggable:false,
			id:'devTreeRoot',
			leaf:false
		},
		dataUrl:'chartData/getDevListGroupCompany.action',
		listeners:{
			click:function(node){
				if(node.leaf==true){
					selectTimeWin(node.attributes.id);
				}
			}
		}
	});
	devTree.root.expand(true,true);
	
	
	var jkPanel = new Ext.Panel({
		id:'jkPanel',
		region:'center',
		autoScroll:true,
		border:false,
		autoLoad:'devJkNodate.jsp',
		tbar:[{
			text:'下载',
			pressed:true,
			handler:function(){
				if(Ext.isEmpty(startD)||Ext.isEmpty(endD)){
					Ext.Msg.alert("提示","没有可下载的数据");
				}else{
					var node = devTree.getSelectionModel().getSelectedNode();
					if(Ext.isEmpty(node)){
						Ext.Msg.alert('提示','没有可下载的数据');
						return ;
					}
					
					if(node.leaf!=true){
						Ext.Msg.alert('提示','没有可下载的数据');
						return ;
					}
					download(node.attributes.id,startD,endD);
				}
			}
		}]
	});
	
	
	function selectTimeWin(devCode){
		var timeForm = new Ext.form.FormPanel({
				id : 'timeForm',
				name : 'timeForm',
				defaultType : 'datefield',
				labelAlign : 'right',
				labelWidth : 65,
				bodyStyle : 'padding:5 5 5 5',
				frame : false,
				items : [{
							fieldLabel:'开始日期',
							allowBlank : false,
							id:'startTime',
							format:'Y-m-d',
							anchor : '99%'
						},{
							fieldLabel : '结束日期',
							id : 'endTime',
							allowBlank : false,
							format:'Y-m-d',
							anchor : '99%'
						}]
			});
		var timeWin = new Ext.Window({
						layout : 'fit',
						width : 280,
						height : 130,
						resizable : false,
						draggable : false,
						closeAction : 'close',
						title : '<span style="font-weight:normal">时间段选择</span>',
						modal : true,
						collapsible : false,
						maximizable : false,
						buttonAlign : 'right',
						border : false,
						animCollapse : true,
						constrain : true,
						items : [timeForm],
						buttons:[{
							text : '确定',
							iconCls : 'acceptIcon',
							handler : function() {
							startD = Ext.util.Format.date(Ext.getCmp('startTime').getValue(),'Y-m-d H:i:s');
							endD = Ext.util.Format.date(Ext.getCmp('endTime').getValue(),'Y-m-d H:i:s');
								jkPanel.load("<%=basePath%>chartData/showJiankang.action?devCode="+devCode+"&startDate="+startD+"&endDate="+endD);
								timeWin.destroy();
							}
						},{
							text:'关闭',
							iconCls : 'acceptIcon',
							handler:function(){
								timeWin.destroy();
							}
						}]
					});
			timeWin.show();
	}
	
	function download(devCode,startDate,endDate){
		var fd=Ext.get('downloadWord');
		if (!fd) {
	        fd=Ext.DomHelper.append(Ext.getBody(),{tag:'form',method:'post',id:'downloadWord',action:'chartData/downloadWord.action',name:'frmDummy',cls:'x-hidden',cn:[
	        	{tag:'input',name:'devCode',id:'devCode001',type:'hidden'},
	            {tag:'input',name:'startDate',id:'startDate001',type:'hidden'},
	            {tag:'input',name:'endDate',id:'endDate001',type:'hidden'},
	        ]},true);
	    }
	    fd.child('#devCode001').set({value:devCode});
	    fd.child('#startDate001').set({value:startDate});
	    fd.child('#endDate001').set({value:endDate});
	    fd.dom.submit();
	}
	
	var view = new Ext.Viewport({
		layout:'border',
		items:[devTree,jkPanel]
	});
});
</script>
  </head>
  <body>
  </body>
</html>
